package com.ljm.controller;/**
 * @author： li
 * @date： 2021-05-18 18:21
 * @version 1.0
 */

import com.ljm.bin.wxuser;
import com.ljm.service.userService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

/**
 * @author： Administrator
 * @date： 2021-05-18 18:21
 * @version 1.0
 */
@WebServlet("/login")
public class loginServlet implements Servlet {
    @Override
    public void init(ServletConfig config) {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws IOException {
            res.setContentType("text/json; charset=utf-8");
            PrintWriter out =res.getWriter();
            JSONArray ja = new JSONArray();
            JSONObject jo = new JSONObject();
                          String username=req.getParameter("username");
                          String password=req.getParameter("password");
                          wxuser us=new wxuser();
                          us.setUsername(username);
                          us.setPassword(password);
                          userService userservice=new userService();
                          int i=0;
        try {
            i=userservice.login(us);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        jo.put("flag",i);
        jo.put("username",username);
        ja.add(jo);
        out.println(ja);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
